﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SqlSugar;
using ZooKeeperManage;

namespace ZooKeeperSamples
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //  readonly DispatchManage _dispatchManage = new DispatchManage();
        private void button1_Click(object sender, EventArgs e)
        {
            //_dispatchManage.Create("22");
            // _dispatchManage.Create("/1/2/3/5");
        }

        private WorkServer _workServer;
        private void button2_Click(object sender, EventArgs e)
        {
            var work = new WorkData() { Name = "asdd" };
            if (_workServer == null)
                _workServer = new WorkServer(work);
            _workServer.Start();
            //  _dispatchManage.GetHashCode()
        }

        private void button3_Click(object sender, EventArgs e)
        {
            _workServer.TakeMaster();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            var s = _workServer.GetChildren();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            _workServer.ReleaseMaster();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            SqlSugarClient db = new SqlSugarClient(
             new ConnectionConfig()
             {
                 ConnectionString = "server=.;uid=sa;pwd=cqjizhi;database=YZIT",
                 DbType = SqlSugar.DbType.SqlServer,//设置数据库类型
                 IsAutoCloseConnection = true,//自动释放数据务，如果存在事务，在事务结束后释放
                 InitKeyType = InitKeyType.Attribute //从实体特性中读取主键自增列信息
             }
         );

            db.Aop.OnLogExecuting = (sql, pars) =>
            {
                string ss = db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value));
                Console.WriteLine(sql + "\r\n" +
                db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
                Console.WriteLine();
            };
            var list = db.Queryable<SysRoleEntity>().ToList();//查询所有

            string s = "";
        }
        private readonly ZooKeeperService _zkService;
        private void button6_Click(object sender, EventArgs e)
        {
            //_zkService.ChildrenChanged("");
        }
    }
    /// <summary> 
    ///Sys_Role 实体
    /// </summary>
    [SugarTable("Sys_Role")]
    public class SysRoleEntity
    {

        /// <summary>
        /// Id
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// EnCode
        /// </summary>
        public string EnCode { get; set; }

        /// <summary>
        /// FullName
        /// </summary>
        public string FullName { get; set; }

        /// <summary>
        /// Type
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// AllowEdit
        /// </summary>
        public bool? AllowEdit { get; set; }

        /// <summary>
        /// AllowDelete
        /// </summary>
        public bool? AllowDelete { get; set; }

        /// <summary>
        /// SortCode
        /// </summary>
        public int? SortCode { get; set; }

        /// <summary>
        /// DeleteMark
        /// </summary>
        public bool? DeleteMark { get; set; }

        /// <summary>
        /// EnabledMark
        /// </summary>
        public bool? EnabledMark { get; set; }

        /// <summary>
        /// Description
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// CreatorTime
        /// </summary>
        public DateTime? CreatorTime { get; set; }

        /// <summary>
        /// CreatorUserId
        /// </summary>
        public string CreatorUserId { get; set; }

        /// <summary>
        /// LastModifyTime
        /// </summary>
        public DateTime? LastModifyTime { get; set; }

        /// <summary>
        /// LastModifyUserId
        /// </summary>
        public string LastModifyUserId { get; set; }

        /// <summary>
        /// DeleteTime
        /// </summary>
        public DateTime? DeleteTime { get; set; }

        /// <summary>
        /// DeleteUserId
        /// </summary>
        public string DeleteUserId { get; set; }
    }
}
